home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / emacs.lha / emacs-19.16 / lisp / rmailsum.el < prev    next >
Lisp/Scheme  |  1993-06-21  |  39KB  |  1,072 lines

  1. ;;; rmailsum.el --- make summary buffers for the mail reader
  2.  
  3. ;; Copyright (C) 1985, 1993 Free Software Foundation, Inc.
  4.  
  5. ;; Maintainer: FSF
  6. ;; Keywords: mail
  7.  
  8. ;; This file is part of GNU Emacs.
  9.  
  10. ;; GNU Emacs is free software; you can redistribute it and/or modify
  11. ;; it under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation; either version 2, or (at your option)
  13. ;; any later version.
  14.  
  15. ;; GNU Emacs is distributed in the hope that it will be useful,
  16. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18. ;; GNU General Public License for more details.
  19.  
  20. ;; You should have received a copy of the GNU General Public License
  21. ;; along with GNU Emacs; see the file COPYING.  If not, write to
  22. ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  
  24. ;;; Commentary:
  25.  
  26. ;; Extended by Bob Weiner of Motorola
  27. ;;   Provided all commands from rmail-mode in rmail-summary-mode and made key
  28. ;;   bindings in both modes wholly compatible.
  29.  
  30. ;;; Code:
  31.  
  32. ;; Entry points for making a summary buffer.
  33.  
  34. ;; Regenerate the contents of the summary
  35. ;; using the same selection criterion as last time.
  36. ;; M-x revert-buffer in a summary buffer calls this function.
  37. (defun rmail-update-summary (&rest ignore)
  38.   (apply (car rmail-summary-redo) (cdr rmail-summary-redo)))
  39.  
  40. (defun rmail-summary ()
  41.   "Display a summary of all messages, one line per message."
  42.   (interactive)
  43.   (rmail-new-summary "All" '(rmail-summary) nil))
  44.  
  45. (defun rmail-summary-by-labels (labels)
  46.   "Display a summary of all messages with one or more LABELS.
  47. LABELS should be a string containing the desired labels, separated by commas."
  48.   (interactive "sLabels to summarize by: ")
  49.   (if (string= labels "")
  50.       (setq labels (or rmail-last-multi-labels
  51.                (error "No label specified"))))
  52.   (setq rmail-last-multi-labels labels)
  53.   (rmail-new-summary (concat "labels " labels)
  54.              (list 'rmail-summary-by-labels labels)
  55.              'rmail-message-labels-p
  56.              (concat ", \\(" (mail-comma-list-regexp labels) "\\),")))
  57.  
  58. (defun rmail-summary-by-recipients (recipients &optional primary-only)
  59.   "Display a summary of all messages with the given RECIPIENTS.
  60. Normally checks the To, From and Cc fields of headers;
  61. but if PRIMARY-ONLY is non-nil (prefix arg given),
  62.  only look in the To and From fields.
  63. RECIPIENTS is a string of regexps separated by commas."
  64.   (interactive "sRecipients to summarize by: \nP")
  65.   (rmail-new-summary
  66.    (concat "recipients " recipients)
  67.    (list 'rmail-summary-by-recipients recipients primary-only)
  68.    'rmail-message-recipients-p
  69.    (mail-comma-list-regexp recipients) primary-only))
  70.  
  71. (defun rmail-summary-by-regexp (regexp)
  72.   "Display a summary of all messages according to regexp REGEXP.
  73. If the regular expression is found in the header of the message
  74. \(including in the date and other lines, as well as the subject line),
  75. Emacs will list the header line in the RMAIL-summary."
  76.   (interactive "sRegexp to summarize by: ")
  77.   (if (string= regexp "")
  78.       (setq regexp (or rmail-last-regexp
  79.              (error "No regexp specified."))))
  80.   (setq rmail-last-regexp regexp)
  81.   (rmail-new-summary (concat "regexp " regexp)
  82.              (list 'rmail-summary-by-regexp regexp)
  83.              'rmail-message-regexp-p
  84.                      regexp))
  85.  
  86. ;; rmail-summary-by-topic
  87. ;; 1989 R.A. Schnitzler
  88.  
  89. (defun rmail-summary-by-topic (subject &optional whole-message)
  90.   "Display a summary of all messages with the given SUBJECT.
  91. Normally checks the Subject field of headers;
  92. but if WHOLE-MESSAGE is non-nil (prefix arg given), 
  93.  look in the whole message.
  94. SUBJECT is a string of regexps separated by commas."
  95.   (interactive "sTopics to summarize by: \nP")
  96.   (rmail-new-summary
  97.    (concat "about " subject)
  98.    (list 'rmail-summary-by-topic subject whole-message)
  99.    'rmail-message-subject-p
  100.    (mail-comma-list-regexp subject) whole-message))
  101.  
  102. (defun rmail-message-subject-p (msg subject &optional whole-message)
  103.   (save-restriction
  104.     (goto-char (rmail-msgbeg msg))
  105.     (search-forward "\n*** EOOH ***\n")
  106.     (narrow-to-region
  107.      (point)
  108.      (progn (search-forward (if whole-message "\^_" "\n\n")) (point)))
  109.     (goto-char (point-min))
  110.     (if whole-message (re-search-forward subject nil t)
  111.       (string-match subject (or (mail-fetch-field "Subject") "")) )))
  112.  
  113. (defun rmail-summary-by-senders (senders)
  114.   "Display a summary of all messages with the given SENDERS.
  115. SENDERS is a string of names separated by commas."
  116.   (interactive "sSenders to summarize by: ")
  117.   (rmail-new-summary
  118.    (concat "senders " senders)
  119.    'rmail-message-senders-p
  120.    (mail-comma-list-regexp senders)))
  121.  
  122. (defun rmail-message-senders-p (msg senders)
  123.   (save-restriction
  124.     (goto-char (rmail-msgbeg msg))
  125.     (search-forward "\n*** EOOH ***\n")
  126.     (narrow-to-region (point) (progn (search-forward "\n\n") (point)))
  127.     (string-match senders (or (mail-fetch-field "From") ""))))
  128.  
  129. ;; General making of a summary buffer.
  130.  
  131. (defvar rmail-summary-symbol-number 0)
  132.  
  133. (defun rmail-new-summary (description redo-form function &rest args)
  134.   "Create a summary of selected messages.
  135. DESCRIPTION makes part of the mode line of the summary buffer.
  136. For each message, FUNCTION is applied to the message number and ARGS...
  137. and if the result is non-nil, that message is included.
  138. nil for FUNCTION means all messages."
  139.   (message "Computing summary lines...")
  140.   (let (sumbuf mesg was-in-summary)
  141.     (save-excursion
  142.       ;; Go to the Rmail buffer.
  143.       (if (eq major-mode 'rmail-summary-mode)
  144.       (progn
  145.         (setq was-in-summary t)
  146.         (set-buffer rmail-buffer)))
  147.       ;; Find its summary buffer, or make one.
  148.       (setq sumbuf
  149.         (if (and rmail-summary-buffer
  150.              (buffer-name rmail-summary-buffer))
  151.         rmail-summary-buffer
  152.           (generate-new-buffer (concat (buffer-name) "-summary"))))
  153.       (setq mesg rmail-current-message)
  154.       ;; Filter the messages; make or get their summary lines.
  155.       (let ((summary-msgs ())
  156.         (new-summary-line-count 0))
  157.     (let ((msgnum 1)
  158.           (buffer-read-only nil))
  159.       (save-restriction
  160.         (save-excursion
  161.           (widen)
  162.           (goto-char (point-min))
  163.           (while (>= rmail-total-messages msgnum)
  164.         (if (or (null function)
  165.             (apply function (cons msgnum args)))
  166.             (setq summary-msgs
  167.               (cons (cons msgnum (rmail-make-summary-line msgnum))
  168.                 summary-msgs)))
  169.         (setq msgnum (1+ msgnum)))
  170.           (setq summary-msgs (nreverse summary-msgs)))))
  171.     ;; Temporarily, while summary buffer is unfinished,
  172.     ;; we "don't have" a summary.
  173.     (setq rmail-summary-buffer nil)
  174.     (save-excursion
  175.       (let ((rbuf (current-buffer))
  176.         (total rmail-total-messages))
  177.         (set-buffer sumbuf)
  178.         ;; Set up the summary buffer's contents.
  179.         (let ((buffer-read-only nil))
  180.           (erase-buffer)
  181.           (while summary-msgs
  182.         (princ (cdr (car summary-msgs)) sumbuf)
  183.         (setq summary-msgs (cdr summary-msgs)))
  184.           (goto-char (point-min)))
  185.         ;; Set up the rest of its state and local variables.
  186.         (setq buffer-read-only t)
  187.         (rmail-summary-mode)
  188.         (make-local-variable 'minor-mode-alist)
  189.         (setq minor-mode-alist (list '(t (concat ": " description))))
  190.         (setq rmail-buffer rbuf
  191.           rmail-summary-redo redo-form
  192.           rmail-total-messages total))))
  193.       (setq rmail-summary-buffer sumbuf))
  194.     ;; Now display the summary buffer and go to the right place in it.
  195.     (or was-in-summary
  196.     (pop-to-buffer sumbuf))
  197.     (rmail-summary-goto-msg mesg t t)
  198.     (message "Computing summary lines...done")))
  199.  
  200. ;; Low levels of generating a summary.
  201.  
  202. (defun rmail-make-summary-line (msg)
  203.   (let ((line (or (aref rmail-summary-vector (1- msg))
  204.           (progn
  205.             (setq new-summary-line-count
  206.               (1+ new-summary-line-count))
  207.             (if (zerop (% new-summary-line-count 10))
  208.             (message "Computing summary lines...%d"
  209.                  new-summary-line-count))
  210.             (rmail-make-summary-line-1 msg)))))
  211.     ;; Fix up the part of the summary that says "deleted" or "unseen".
  212.     (aset line 4
  213.       (if (rmail-message-deleted-p msg) ?\D
  214.         (if (= ?0 (char-after (+ 3 (rmail-msgbeg msg))))
  215.         ?\- ?\ )))
  216.     line))
  217.  
  218. (defun rmail-make-summary-line-1 (msg)
  219.   (goto-char (rmail-msgbeg msg))
  220.   (let* ((lim (save-excursion (forward-line 2) (point)))
  221.      pos
  222.      (labels
  223.       (progn
  224.         (forward-char 3)
  225.         (concat
  226. ;         (if (save-excursion (re-search-forward ",answered," lim t))
  227. ;         "*" "")
  228. ;         (if (save-excursion (re-search-forward ",filed," lim t))
  229. ;         "!" "")
  230.          (if (progn (search-forward ",,") (eolp))
  231.          ""
  232.            (concat "{"
  233.                (buffer-substring (point)
  234.                      (progn (end-of-line) (point)))
  235.                "} ")))))
  236.      (line
  237.       (progn
  238.         (forward-line 1)
  239.         (if (looking-at "Summary-line: ")
  240.         (progn
  241.           (goto-char (match-end 0))
  242.           (setq line
  243.             (buffer-substring (point)
  244.                       (progn (forward-line 1) (point)))))))))
  245.     ;; Obsolete status lines lacking a # should be flushed.
  246.     (and line
  247.      (not (string-match "#" line))
  248.      (progn
  249.        (delete-region (point)
  250.               (progn (forward-line -1) (point)))
  251.        (setq line nil)))
  252.     ;; If we didn't get a valid status line from the message,
  253.     ;; make a new one and put it in the message.
  254.     (or line
  255.     (let* ((case-fold-search t)
  256.            (next (rmail-msgend msg))
  257.            (beg (if (progn (goto-char (rmail-msgbeg msg))
  258.                    (search-forward "\n*** EOOH ***\n" next t))
  259.             (point)
  260.               (forward-line 1)
  261.               (point)))
  262.            (end (progn (search-forward "\n\n" nil t) (point))))
  263.       (save-restriction
  264.         (narrow-to-region beg end)
  265.         (goto-char beg)
  266.         (setq line (rmail-make-basic-summary-line)))
  267.       (goto-char (rmail-msgbeg msg))
  268.       (forward-line 2)
  269.       (insert "Summary-line: " line)))
  270.     (setq pos (string-match "#" line))
  271.     (aset rmail-summary-vector (1- msg)
  272.       (concat (format "%4d  " msg)
  273.           (substring line 0 pos)
  274.           labels
  275.           (substring line (1+ pos))))))
  276.  
  277. (defun rmail-make-basic-summary-line ()
  278.   (goto-char (point-min))
  279.   (concat (save-excursion
  280.         (if (not (re-search-forward "^Date:" nil t))
  281.         "      "
  282.           (cond ((re-search-forward "\\([^0-9:]\\)\\([0-3]?[0-9]\\)\\([- \t_]+\\)\\([adfjmnos][aceopu][bcglnprtvy]\\)"
  283.               (save-excursion (end-of-line) (point)) t)
  284.              (format "%2d-%3s"
  285.                  (string-to-int (buffer-substring
  286.                          (match-beginning 2)
  287.                          (match-end 2)))
  288.                  (buffer-substring
  289.                   (match-beginning 4) (match-end 4))))
  290.             ((re-search-forward "\\([^a-z]\\)\\([adfjmnos][acepou][bcglnprtvy]\\)\\([-a-z \t_]*\\)\\([0-9][0-9]?\\)"
  291.               (save-excursion (end-of-line) (point)) t)
  292.              (format "%2d-%3s"
  293.                  (string-to-int (buffer-substring
  294.                          (match-beginning 4)
  295.                          (match-end 4)))
  296.                  (buffer-substring
  297.                   (match-beginning 2) (match-end 2))))
  298.             (t "??????"))))
  299.       "  "
  300.       (save-excursion
  301.         (if (not (re-search-forward "^From:[ \t]*" nil t))
  302.         "                         "
  303.           (let* ((from (mail-strip-quoted-names
  304.                 (buffer-substring
  305.                  (1- (point))
  306.                  (progn (end-of-line)
  307.                     (skip-chars-backward " \t")
  308.                     (point)))))
  309.              len mch lo)
  310.         (if (string-match (concat "^"
  311.                       (regexp-quote (user-login-name))
  312.                       "\\($\\|@\\)")
  313.                   from)
  314.             (save-excursion
  315.               (goto-char (point-min))
  316.               (if (not (re-search-forward "^To:[ \t]*" nil t))
  317.               nil
  318.             (setq from
  319.                   (concat "to: "
  320.                       (mail-strip-quoted-names
  321.                        (buffer-substring
  322.                     (point)
  323.                     (progn (end-of-line)
  324.                            (skip-chars-backward " \t")
  325.                            (point)))))))))
  326.         (setq len (length from))
  327.         (setq mch (string-match "[@%]" from))
  328.         (format "%25s"
  329.             (if (or (not mch) (<= len 25))
  330.                 (substring from (max 0 (- len 25)))
  331.               (substring from
  332.                      (setq lo (cond ((< (- mch 9) 0) 0)
  333.                             ((< len (+ mch 16))
  334.                              (- len 25))
  335.                             (t (- mch 9))))
  336.                      (min len (+ lo 25))))))))
  337.       "  #"
  338.       (if (re-search-forward "^Subject:" nil t)
  339.           (progn (skip-chars-forward " \t")
  340.              (buffer-substring (point)
  341.                        (progn (end-of-line)
  342.                           (point))))
  343.         (re-search-forward "[\n][\n]+" nil t)
  344.         (buffer-substring (point) (progn (end-of-line) (point))))
  345.       "\n"))
  346.  
  347. ;; Simple motion in a summary buffer.
  348.  
  349. (defun rmail-summary-next-all (&optional number)
  350.   (interactive "p")
  351.   (forward-line (if number number 1))
  352.   (display-buffer rmail-buffer))
  353.  
  354. (defun rmail-summary-previous-all (&optional number)
  355.   (interactive "p")
  356.   (forward-line (- (if number number 1)))
  357.   (display-buffer rmail-buffer))
  358.  
  359. (defun rmail-summary-next-msg (&optional number)
  360.   "Display next non-deleted msg from rmail file.
  361. With optional prefix argument NUMBER, moves forward this number of non-deleted
  362. messages, or backward if NUMBER is negative."
  363.   (interactive "p")
  364.   (forward-line 0)
  365.   (and (> number 0) (end-of-line))
  366.   (let ((count (if (< number 0) (- number) number))
  367.     (search (if (> number 0) 're-search-forward 're-search-backward))
  368.     (non-del-msg-found nil))
  369.     (while (and (> count 0) (setq non-del-msg-found
  370.                   (or (funcall search "^....[^D]" nil t)
  371.                       non-del-msg-found)))
  372.       (setq count (1- count))))
  373.   (beginning-of-line)
  374.   (display-buffer rmail-buffer))
  375.  
  376. (defun rmail-summary-previous-msg (&optional number)
  377.   (interactive "p")
  378.   (rmail-summary-next-msg (- (if number number 1))))
  379.  
  380. (defun rmail-summary-next-labeled-message (n labels)
  381.   "Show next message with LABEL.  Defaults to last labels used.
  382. With prefix argument N moves forward N messages with these labels."
  383.   (interactive "p\nsMove to next msg with labels: ")
  384.   (save-excursion
  385.     (set-buffer rmail-buffer)
  386.     (rmail-next-labeled-message n labels)))
  387.  
  388. (defun rmail-summary-previous-labeled-message (n labels)
  389.   "Show previous message with LABEL.  Defaults to last labels used.
  390. With prefix argument N moves backward N messages with these labels."
  391.   (interactive "p\nsMove to previous msg with labels: ")
  392.   (save-excursion
  393.     (set-buffer rmail-buffer)
  394.     (rmail-previous-labeled-message n labels)))
  395.  
  396. ;; Delete and undelete summary commands.
  397.  
  398. (defun rmail-summary-delete-forward (&optional backward)
  399.   "Delete this message and move to next nondeleted one.
  400. Deleted messages stay in the file until the \\[rmail-expunge] command is given.
  401. With prefix argument, delete and move backward."
  402.   (interactive "P")
  403.   (let (end)
  404.     (rmail-summary-goto-msg)
  405.     (pop-to-buffer rmail-buffer)
  406.     (rmail-delete-forward backward)
  407.     (pop-to-buffer rmail-summary-buffer)))
  408.  
  409. (defun rmail-summary-delete-backward ()
  410.   "Delete this message and move to previous nondeleted one.
  411. Deleted messages stay in the file until the \\[rmail-expunge] command is given."
  412.   (interactive)
  413.   (rmail-summary-delete-forward t))
  414.  
  415. (defun rmail-summary-mark-deleted (&optional n undel)
  416.   (and n (rmail-summary-goto-msg n t t))
  417.   (or (eobp)
  418.       (let ((buffer-read-only nil))
  419.     (skip-chars-forward " ")
  420.     (skip-chars-forward "[0-9]")
  421.     (if undel
  422.         (if (looking-at "D")
  423.         (progn (delete-char 1) (insert " ")))
  424.       (delete-char 1)
  425.       (insert "D"))))
  426.   (beginning-of-line))
  427.  
  428. (defun rmail-summary-mark-undeleted (n)
  429.   (rmail-summary-mark-deleted n t))
  430.  
  431. (defun rmail-summary-deleted-p (&optional n)
  432.   (save-excursion
  433.     (and n (rmail-summary-goto-msg n nil t))
  434.     (skip-chars-forward " ")
  435.     (skip-chars-forward "[0-9]")
  436.     (looking-at "D")))
  437.  
  438. (defun rmail-summary-undelete (&optional arg)
  439.   "Undelete current message.
  440. Optional prefix ARG means undelete ARG previous messages."
  441.   (interactive "p")
  442.   (if (/= arg 1)
  443.       (rmail-summary-undelete-many arg)
  444.     (let ((buffer-read-only nil))
  445.       (end-of-line)
  446.       (cond ((re-search-backward "\\(^ *[0-9]*\\)\\(D\\)" nil t)
  447.          (replace-match "\\1 ")
  448.          (rmail-summary-goto-msg)
  449.          (pop-to-buffer rmail-buffer)
  450.          (and (rmail-message-deleted-p rmail-current-message)
  451.           (rmail-undelete-previous-message))
  452.          (pop-to-buffer rmail-summary-buffer))))))
  453.  
  454. (defun rmail-summary-undelete-many (&optional n)
  455.   "Undelete all deleted msgs, optional prefix arg N means undelete N prev msgs."
  456.   (interactive "P")
  457.   (save-excursion
  458.     (set-buffer rmail-buffer)
  459.     (let* ((init-msg (if n rmail-current-message rmail-total-messages))
  460.        (rmail-current-message init-msg)
  461.        (n (or n rmail-total-messages))
  462.        (msgs-undeled 0))
  463.       (while (and (> rmail-current-message 0)
  464.           (< msgs-undeled n))
  465.     (if (rmail-message-deleted-p rmail-current-message)
  466.         (progn (rmail-set-attribute "deleted" nil)
  467.            (setq msgs-undeled (1+ msgs-undeled))))
  468.     (setq rmail-current-message (1- rmail-current-message)))
  469.       (set-buffer rmail-summary-buffer)
  470.       (setq rmail-current-message init-msg msgs-undeled 0)
  471.       (while (and (> rmail-current-message 0)
  472.           (< msgs-undeled n))
  473.     (if (rmail-summary-deleted-p rmail-current-message)
  474.         (progn (rmail-summary-mark-undeleted rmail-current-message)
  475.            (setq msgs-undeled (1+ msgs-undeled))))
  476.     (setq rmail-current-message (1- rmail-current-message))))
  477.     (rmail-summary-goto-msg)))
  478.  
  479. ;; Rmail Summary mode is suitable only for specially formatted data.
  480. (put 'rmail-summary-mode 'mode-class 'special)
  481.  
  482. (defun rmail-summary-mode ()
  483.   "Rmail Summary Mode is invoked from Rmail Mode by using \\<rmail-mode-map>\\[rmail-summary].
  484. As commands are issued in the summary buffer, they are applied to the
  485. corresponding mail messages in the rmail buffer.
  486.  
  487. All normal editing commands are turned off.
  488. Instead, all of the Rmail Mode commands are available, plus:
  489.  
  490. \\[rmail-summary-undelete-many]    Undelete all or prefix arg deleted messages."
  491.   (interactive)
  492.   (kill-all-local-variables)
  493.   (setq major-mode 'rmail-summary-mode)
  494.   (setq mode-name "RMAIL Summary")
  495.   (use-local-map rmail-summary-mode-map)
  496.   (setq truncate-lines t)
  497.   (setq buffer-read-only t)
  498.   (set-syntax-table text-mode-syntax-table)
  499.   (make-local-variable 'rmail-buffer)
  500.   (make-local-variable 'rmail-total-messages)
  501.   (make-local-variable 'rmail-current-message)
  502.   (setq rmail-current-message nil)
  503.   (make-local-variable 'rmail-summary-redo)
  504.   (setq rmail-summary-redo nil)
  505.   (make-local-variable 'revert-buffer-function)
  506.   (setq revert-buffer-function 'rmail-update-summary)
  507.   (make-local-variable 'post-command-hook)
  508.   (add-hook 'post-command-hook 'rmail-summary-rmail-update)
  509.   (run-hooks 'rmail-summary-mode-hook))
  510.  
  511. ;; Show in Rmail the message described by the summary line that point is on,
  512. ;; but only if the Rmail buffer is already visible.
  513. ;; This is a post-command-hook in summary buffers.
  514. (defun rmail-summary-rmail-update ()
  515.   (if (get-buffer-window rmail-buffer)
  516.       (let (buffer-read-only)
  517.     (save-excursion
  518.       (beginning-of-line)
  519.       (skip-chars-forward " ")
  520.       (let ((beg (point))
  521.         msg-num
  522.         (buf rmail-buffer))
  523.         (skip-chars-forward "0-9")
  524.         (setq msg-num (string-to-int (buffer-substring beg (point))))
  525.         (or (eq rmail-current-message msg-num)
  526.         (let (go-where window (owin (selected-window)))
  527.           (setq rmail-current-message msg-num)
  528.           (if (= (following-char) ?-)
  529.               (progn
  530.             (delete-char 1)
  531.             (insert " ")))
  532.           (setq window (display-buffer rmail-buffer))
  533.           ;; Using save-window-excursion caused the new value
  534.           ;; of point to get lost.
  535.           (unwind-protect
  536.               (progn
  537.             (select-window window)
  538.             (rmail-show-message msg-num))
  539.             (select-window owin)))))))))
  540.  
  541. (defvar rmail-summary-mode-map nil)
  542.  
  543. (if rmail-summary-mode-map
  544.     nil
  545.   (setq rmail-summary-mode-map (make-keymap))
  546.   (suppress-keymap rmail-summary-mode-map)
  547.   (define-key rmail-summary-mode-map "a"      'rmail-summary-add-label)
  548.   (define-key rmail-summary-mode-map "c"      'rmail-summary-continue)
  549.   (define-key rmail-summary-mode-map "d"      'rmail-summary-delete-forward)
  550.   (define-key rmail-summary-mode-map "\C-d"   'rmail-summary-delete-backward)
  551.   (define-key rmail-summary-mode-map "e"      'rmail-summary-edit-current-message)
  552.   (define-key rmail-summary-mode-map "f"      'rmail-summary-forward)
  553.   (define-key rmail-summary-mode-map "g"      'rmail-summary-get-new-mail)
  554.   (define-key rmail-summary-mode-map "h"      'rmail-summary)
  555.   (define-key rmail-summary-mode-map "i"      'rmail-summary-input)
  556.   (define-key rmail-summary-mode-map "j"      'rmail-summary-goto-msg)
  557.   (define-key rmail-summary-mode-map "k"      'rmail-summary-kill-label)
  558.   (define-key rmail-summary-mode-map "l"      'rmail-summary-by-labels)
  559.   (define-key rmail-summary-mode-map "\e\C-h" 'rmail-summary)
  560.   (define-key rmail-summary-mode-map "\e\C-l" 'rmail-summary-by-labels)
  561.   (define-key rmail-summary-mode-map "\e\C-r" 'rmail-summary-by-recipients)
  562.   (define-key rmail-summary-mode-map "\e\C-s" 'rmail-summary-by-regexp)
  563.   (define-key rmail-summary-mode-map "\e\C-t" 'rmail-summary-by-topic)
  564.   (define-key rmail-summary-mode-map "m"      'rmail-summary-mail)
  565.   (define-key rmail-summary-mode-map "\M-m"   'rmail-summary-retry-failure)
  566.   (define-key rmail-summary-mode-map "n"      'rmail-summary-next-msg)
  567.   (define-key rmail-summary-mode-map "\en"    'rmail-summary-next-all)
  568.   (define-key rmail-summary-mode-map "\e\C-n" 'rmail-summary-next-labeled-message)
  569.   (define-key rmail-summary-mode-map "o"      'rmail-summary-output-to-rmail-file)
  570.   (define-key rmail-summary-mode-map "\C-o"   'rmail-summary-output)
  571.   (define-key rmail-summary-mode-map "p"      'rmail-summary-previous-msg)
  572.   (define-key rmail-summary-mode-map "\ep"    'rmail-summary-previous-all)
  573.   (define-key rmail-summary-mode-map "\e\C-p" 'rmail-summary-previous-labeled-message)
  574.   (define-key rmail-summary-mode-map "q"      'rmail-summary-quit)
  575.   (define-key rmail-summary-mode-map "r"      'rmail-summary-reply)
  576.   (define-key rmail-summary-mode-map "s"      'rmail-summary-expunge-and-save)
  577.   (define-key rmail-summary-mode-map "\es"    'rmail-summary-search)
  578.   (define-key rmail-summary-mode-map "t"      'rmail-summary-toggle-header)
  579.   (define-key rmail-summary-mode-map "u"      'rmail-summary-undelete)
  580.   (define-key rmail-summary-mode-map "\M-u"   'rmail-summary-undelete-many)
  581.   (define-key rmail-summary-mode-map "w"      'rmail-summary-wipe)
  582.   (define-key rmail-summary-mode-map "x"      'rmail-summary-expunge)
  583.   (define-key rmail-summary-mode-map "."      'rmail-summary-beginning-of-message)
  584.   (define-key rmail-summary-mode-map "<"      'rmail-summary-first-message)
  585.   (define-key rmail-summary-mode-map ">"      'rmail-summary-last-message)
  586.   (define-key rmail-summary-mode-map " "      'rmail-summary-scroll-msg-up)
  587.   (define-key rmail-summary-mode-map "\177"   'rmail-summary-scroll-msg-down)
  588.   (define-key rmail-summary-mode-map "?"      'describe-mode)
  589.   (define-key rmail-summary-mode-map "\C-c\C-s\C-d"
  590.     'rmail-summary-sort-by-date)
  591.   (define-key rmail-summary-mode-map "\C-c\C-s\C-s"
  592.     'rmail-summary-sort-by-subject)
  593.   (define-key rmail-summary-mode-map "\C-c\C-s\C-a"
  594.     'rmail-summary-sort-by-author)
  595.   (define-key rmail-summary-mode-map "\C-c\C-s\C-r"
  596.     'rmail-summary-sort-by-recipient)
  597.   (define-key rmail-summary-mode-map "\C-c\C-s\C-c"
  598.     'rmail-summary-sort-by-correspondent)
  599.   (define-key rmail-summary-mode-map "\C-c\C-s\C-l"
  600.     'rmail-summary-sort-by-lines)
  601.   )
  602.  
  603. ;;; Menu bar bindings.
  604.  
  605. (define-key rmail-summary-mode-map [menu-bar] (make-sparse-keymap))
  606.  
  607. (define-key rmail-summary-mode-map [menu-bar classify]
  608.   (cons "Classify" (make-sparse-keymap "Classify")))
  609.  
  610. (define-key rmail-summary-mode-map [menu-bar classify output-inbox]
  611.   '("Output (inbox)" . rmail-summary-output))
  612.  
  613. (define-key rmail-summary-mode-map [menu-bar classify output]
  614.   '("Output (Rmail)" . rmail-summary-output-to-rmail-file))
  615.  
  616. (define-key rmail-summary-mode-map [menu-bar classify kill-label]
  617.   '("Kill Label" . rmail-summary-kill-label))
  618.  
  619. (define-key rmail-summary-mode-map [menu-bar classify add-label]
  620.   '("Add Label" . rmail-summary-add-label))
  621.  
  622. (define-key rmail-summary-mode-map [menu-bar summary]
  623.   (cons "Summary" (make-sparse-keymap "Summary")))
  624.  
  625. (define-key rmail-summary-mode-map [menu-bar summary labels]
  626.   '("By Labels" . rmail-summary-by-labels))
  627.  
  628. (define-key rmail-summary-mode-map [menu-bar summary recipients]
  629.   '("By Recipients" . rmail-summary-by-recipients))
  630.  
  631. (define-key rmail-summary-mode-map [menu-bar summary topic]
  632.   '("By Topic" . rmail-summary-by-topic))
  633.  
  634. (define-key rmail-summary-mode-map [menu-bar summary regexp]
  635.   '("By Regexp" . rmail-summary-by-regexp))
  636.  
  637. (define-key rmail-summary-mode-map [menu-bar summary all]
  638.   '("All" . rmail-summary))
  639.  
  640. (define-key rmail-summary-mode-map [menu-bar mail]
  641.   (cons "Mail" (make-sparse-keymap "Mail")))
  642.  
  643. (define-key rmail-summary-mode-map [menu-bar mail continue]
  644.   '("Continue" . rmail-summary-continue))
  645.  
  646. (define-key rmail-summary-mode-map [menu-bar mail forward]
  647.   '("Forward" . rmail-summary-forward))
  648.  
  649. (define-key rmail-summary-mode-map [menu-bar mail retry]
  650.   '("Retry" . rmail-summary-retry-failure))
  651.  
  652. (define-key rmail-summary-mode-map [menu-bar mail reply]
  653.   '("Reply" . rmail-summary-reply))
  654.  
  655. (define-key rmail-summary-mode-map [menu-bar mail mail]
  656.   '("Mail" . rmail-summary-mail))
  657.  
  658. (define-key rmail-summary-mode-map [menu-bar delete]
  659.   (cons "Delete" (make-sparse-keymap "Delete")))
  660.  
  661. (define-key rmail-summary-mode-map [menu-bar delete expunge/save]
  662.   '("Expunge/Save" . rmail-summary-expunge-and-save))
  663.  
  664. (define-key rmail-summary-mode-map [menu-bar delete expunge]
  665.   '("Expunge" . rmail-summary-expunge))
  666.  
  667. (define-key rmail-summary-mode-map [menu-bar delete undelete]
  668.   '("Undelete" . rmail-summary-undelete))
  669.  
  670. (define-key rmail-summary-mode-map [menu-bar delete delete]
  671.   '("Delete" . rmail-summary-delete-forward))
  672.  
  673. (define-key rmail-summary-mode-map [menu-bar move]
  674.   (cons "Move" (make-sparse-keymap "Move")))
  675.  
  676. (define-key rmail-summary-mode-map [menu-bar move search-back]
  677.   '("Search Back" . rmail-summary-search-backward))
  678.  
  679. (define-key rmail-summary-mode-map [menu-bar move search]
  680.   '("Search" . rmail-summary-search))
  681.  
  682. (define-key rmail-summary-mode-map [menu-bar move previous]
  683.   '("Previous Nondeleted" . rmail-summary-previous-msg))
  684.  
  685. (define-key rmail-summary-mode-map [menu-bar move next]
  686.   '("Next Nondeleted" . rmail-summary-next-msg))
  687.  
  688. (define-key rmail-summary-mode-map [menu-bar move last]
  689.   '("Last" . rmail-summary-last-message))
  690.  
  691. (define-key rmail-summary-mode-map [menu-bar move first]
  692.   '("First" . rmail-summary-first-message))
  693.  
  694. (define-key rmail-summary-mode-map [menu-bar move previous]
  695.   '("Previous" . rmail-summary-previous-all))
  696.  
  697. (define-key rmail-summary-mode-map [menu-bar move next]
  698.   '("Next" . rmail-summary-next-all))
  699.  
  700. (defun rmail-summary-goto-msg (&optional n nowarn skip-rmail)
  701.   (interactive "P")
  702.   (if (consp n) (setq n (prefix-numeric-value n)))
  703.   (if (eobp) (forward-line -1))
  704.   (beginning-of-line)
  705.   (let ((buf rmail-buffer)
  706.     (cur (point))
  707.     (curmsg (string-to-int
  708.          (buffer-substring (point)
  709.                    (min (point-max) (+ 5 (point)))))))
  710.     (if (not n)
  711.     (setq n curmsg)
  712.       (if (< n 1)
  713.       (progn (message "No preceding message")
  714.          (setq n 1)))
  715.       (if (> n rmail-total-messages)
  716.       (progn (message "No following message")
  717.          (goto-char (point-max))
  718.          (rmail-summary-goto-msg)))
  719.       (goto-char (point-min))
  720.       (if (not (re-search-forward (concat "^ *" (int-to-string n)) nil t))
  721.       (progn (or nowarn (message "Message %d not found" n))
  722.          (setq n curmsg)
  723.          (goto-char cur))))
  724.     (beginning-of-line)
  725.     (skip-chars-forward " ")
  726.     (skip-chars-forward "0-9")
  727.     (save-excursion (if (= (following-char) ?-)
  728.             (let ((buffer-read-only nil))
  729.               (delete-char 1)
  730.               (insert " "))))
  731.     (beginning-of-line)
  732.     (if skip-rmail
  733.     nil
  734.       (pop-to-buffer buf)
  735.       (rmail-show-message n)
  736.       (pop-to-buffer rmail-summary-buffer))))
  737.  
  738. (defun rmail-summary-scroll-msg-up (&optional dist)
  739.   "Scroll other window forward."
  740.   (interactive "P")
  741.   (scroll-other-window dist))
  742.  
  743. (defun rmail-summary-scroll-msg-down (&optional dist)
  744.   "Scroll other window backward."
  745.   (interactive "P")
  746.   (scroll-other-window
  747.    (cond ((eq dist '-) nil)
  748.      ((null dist) '-)
  749.      (t (- (prefix-numeric-value dist))))))
  750.  
  751. (defun rmail-summary-beginning-of-message ()
  752.   "Show current message from the beginning."
  753.   (interactive)
  754.   (pop-to-buffer rmail-buffer)
  755.   (beginning-of-buffer)
  756.   (pop-to-buffer rmail-summary-buffer))
  757.  
  758. (defun rmail-summary-quit ()
  759.   "Quit out of Rmail and Rmail summary."
  760.   (interactive)
  761.   (rmail-summary-wipe)
  762.   (rmail-quit))
  763.  
  764. (defun rmail-summary-wipe ()
  765.   "Kill and wipe away Rmail summary, remaining within Rmail."
  766.   (interactive)
  767.   (save-excursion (set-buffer rmail-buffer) (setq rmail-summary-buffer nil))
  768.   (let ((rmail-wind (get-buffer-window rmail-buffer)))
  769.     (kill-buffer (current-buffer))
  770.     ;; Delete window if not only one.
  771.     (if (not (eq (selected-window) (next-window nil 'no-minibuf)))
  772.     (delete-window))
  773.     ;; Switch to the rmail buffer in this window.
  774.       ;; Select the window with rmail in it, then delete this window.
  775.     (and rmail-wind (select-window rmail-wind))))
  776.  
  777. (defun rmail-summary-expunge ()
  778.   "Actually erase all deleted messages and recompute summary headers."
  779.   (interactive)
  780.   (save-excursion
  781.     (set-buffer rmail-buffer)
  782.     (rmail-only-expunge))
  783.   (rmail-update-summary))
  784.  
  785. (defun rmail-summary-expunge-and-save ()
  786.   "Expunge and save RMAIL file."
  787.   (interactive)
  788.   (save-excursion
  789.     (set-buffer rmail-buffer)
  790.     (rmail-only-expunge))
  791.   (rmail-update-summary)
  792.   (save-excursion
  793.     (set-buffer rmail-buffer)
  794.     (save-buffer)))
  795.  
  796. (defun rmail-summary-get-new-mail ()
  797.   "Get new mail and recompute summary headers."
  798.   (interactive)
  799.   (let (msg)
  800.     (save-excursion
  801.       (set-buffer rmail-buffer)
  802.       (rmail-get-new-mail)
  803.       ;; Get the proper new message number.
  804.       (setq msg rmail-current-message))
  805.     ;; Make sure that message is displayed.
  806.     (rmail-summary-goto-msg msg)))
  807.  
  808. (defun rmail-summary-input (filename)
  809.   "Run Rmail on file FILENAME."
  810.   (interactive "FRun rmail on RMAIL file: ")
  811.   ;; We switch windows here, then display the other Rmail file there.
  812.   (pop-to-buffer rmail-buffer)
  813.   (rmail filename))
  814.  
  815. (defun rmail-summary-first-message ()
  816.   "Show first message in Rmail file from summary buffer."
  817.   (interactive)
  818.   (beginning-of-buffer))
  819.  
  820. (defun rmail-summary-last-message ()
  821.   "Show last message in Rmail file from summary buffer."
  822.   (interactive)
  823.   (end-of-buffer)
  824.   (forward-line -1))
  825.  
  826. (defvar rmail-summary-edit-map nil)
  827. (if rmail-summary-edit-map
  828.     nil
  829.   (setq rmail-summary-edit-map
  830.     (nconc (make-sparse-keymap) (cdr text-mode-map)))
  831.   (define-key rmail-summary-edit-map "\C-c\C-c" 'rmail-cease-edit)
  832.   (define-key rmail-summary-edit-map "\C-c\C-]" 'rmail-abort-edit))
  833.  
  834. (defun rmail-summary-edit-current-message ()
  835.   "Edit the contents of this message."
  836.   (interactive)
  837.   (pop-to-buffer rmail-buffer)
  838.   (rmail-edit-current-message)
  839.   (use-local-map rmail-summary-edit-map))
  840.  
  841. (defun rmail-summary-cease-edit ()
  842.   "Finish editing message, then go back to Rmail summary buffer."
  843.   (interactive)
  844.   (rmail-cease-edit)
  845.   (pop-to-buffer rmail-summary-buffer))
  846.  
  847. (defun rmail-summary-abort-edit ()
  848.   "Abort edit of current message; restore original contents.
  849. Go back to summary buffer."
  850.   (interactive)
  851.   (rmail-abort-edit)
  852.   (pop-to-buffer rmail-summary-buffer))
  853.  
  854. (defun rmail-summary-search-backward (regexp &optional n)
  855.   "Show message containing next match for REGEXP.
  856. Prefix argument gives repeat count; negative argument means search
  857. backwards (through earlier messages).
  858. Interactively, empty argument means use same regexp used last time."
  859.   (interactive
  860.     (let* ((reversep (>= (prefix-numeric-value current-prefix-arg) 0))
  861.        (prompt
  862.         (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
  863.        regexp)
  864.       (if rmail-search-last-regexp
  865.       (setq prompt (concat prompt
  866.                    "(default "
  867.                    rmail-search-last-regexp
  868.                    ") ")))
  869.       (setq regexp (read-string prompt))
  870.       (cond ((not (equal regexp ""))
  871.          (setq rmail-search-last-regexp regexp))
  872.         ((not rmail-search-last-regexp)
  873.          (error "No previous Rmail search string")))
  874.       (list rmail-search-last-regexp
  875.         (prefix-numeric-value current-prefix-arg))))
  876.   ;; Don't use save-excursion because that prevents point from moving
  877.   ;; properly in the summary buffer.
  878.   (let ((buffer (current-buffer)))
  879.     (unwind-protect
  880.     (progn
  881.       (set-buffer rmail-buffer)
  882.       (rmail-search regexp (- n)))
  883.       (set-buffer buffer))))
  884.  
  885. (defun rmail-summary-search (regexp &optional n)
  886.   "Show message containing next match for REGEXP.
  887. Prefix argument gives repeat count; negative argument means search
  888. backwards (through earlier messages).
  889. Interactively, empty argument means use same regexp used last time."
  890.   (interactive
  891.     (let* ((reversep (< (prefix-numeric-value current-prefix-arg) 0))
  892.        (prompt
  893.         (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
  894.        regexp)
  895.       (if rmail-search-last-regexp
  896.       (setq prompt (concat prompt
  897.                    "(default "
  898.                    rmail-search-last-regexp
  899.                    ") ")))
  900.       (setq regexp (read-string prompt))
  901.       (cond ((not (equal regexp ""))
  902.          (setq rmail-search-last-regexp regexp))
  903.         ((not rmail-search-last-regexp)
  904.          (error "No previous Rmail search string")))
  905.       (list rmail-search-last-regexp
  906.         (prefix-numeric-value current-prefix-arg))))
  907.   ;; Don't use save-excursion because that prevents point from moving
  908.   ;; properly in the summary buffer.
  909.   (let ((buffer (current-buffer)))
  910.     (unwind-protect
  911.     (progn
  912.       (set-buffer rmail-buffer)
  913.       (rmail-search regexp n))
  914.       (set-buffer buffer))))
  915.  
  916. (defun rmail-summary-toggle-header ()
  917.   "Show original message header if pruned header currently shown, or vice versa."
  918.   (interactive)
  919.   (save-excursion
  920.     (set-buffer rmail-buffer)
  921.     (rmail-toggle-header)))
  922.  
  923. (defun rmail-summary-add-label (label)
  924.   "Add LABEL to labels associated with current Rmail message.
  925. Completion is performed over known labels when reading."
  926.   (interactive (list (save-excursion
  927.                (set-buffer rmail-buffer)
  928.                (rmail-read-label "Add label"))))
  929.   (save-excursion
  930.     (set-buffer rmail-buffer)
  931.     (rmail-add-label label)))
  932.  
  933. (defun rmail-summary-kill-label (label)
  934.   "Remove LABEL from labels associated with current Rmail message.
  935. Completion is performed over known labels when reading."
  936.   (interactive (list (save-excursion
  937.                (set-buffer rmail-buffer)
  938.                (rmail-read-label "Kill label"))))
  939.   (save-excursion
  940.     (set-buffer rmail-buffer)
  941.     (rmail-set-label label nil)))
  942.  
  943. ;;;; *** Rmail Summary Mailing Commands ***
  944.  
  945. (defun rmail-summary-mail ()
  946.   "Send mail in another window.
  947. While composing the message, use \\[mail-yank-original] to yank the
  948. original message into it."
  949.   (interactive)
  950.   (mail-other-window nil nil nil nil nil rmail-buffer)
  951.   (use-local-map (copy-keymap (current-local-map)))
  952.   (define-key (current-local-map)
  953.     "\C-c\C-c" 'rmail-summary-send-and-exit))
  954.  
  955. (defun rmail-summary-continue ()
  956.   "Continue composing outgoing message previously being composed."
  957.   (interactive)
  958.   (mail-other-window t))
  959.  
  960. (defun rmail-summary-reply (just-sender)
  961.   "Reply to the current message.
  962. Normally include CC: to all other recipients of original message;
  963. prefix argument means ignore them.
  964. While composing the reply, use \\[mail-yank-original] to yank the
  965. original message into it."
  966.   (interactive "P")
  967.   (let (mailbuf)
  968.     (save-window-excursion
  969.       (set-buffer rmail-buffer)
  970.       (rmail-reply just-sender)
  971.       (setq mailbuf (current-buffer)))
  972.     (pop-to-buffer mailbuf)
  973.     (use-local-map (copy-keymap (current-local-map)))
  974.     (define-key (current-local-map)
  975.       "\C-c\C-c" 'rmail-summary-send-and-exit)))
  976.  
  977. (defun rmail-summary-retry-failure ()
  978.   "Edit a mail message which is based on the contents of the current message.
  979. For a message rejected by the mail system, extract the interesting headers and
  980. the body of the original message; otherwise copy the current message."
  981.   (interactive)
  982.   (let (mailbuf)
  983.     (save-window-excursion
  984.       (set-buffer rmail-buffer)
  985.       (rmail-retry-failure)
  986.       (setq mailbuf (current-buffer)))
  987.     (pop-to-buffer mailbuf)
  988.     (use-local-map (copy-keymap (current-local-map)))
  989.     (define-key (current-local-map)
  990.       "\C-c\C-c" 'rmail-summary-send-and-exit)))
  991.  
  992. (defun rmail-summary-send-and-exit ()
  993.   "Send mail reply and return to summary buffer."
  994.   (interactive)
  995.   (mail-send-and-exit t))
  996.  
  997. (defun rmail-summary-forward ()
  998.   "Forward the current message to another user."
  999.   (interactive)
  1000.   (save-excursion
  1001.     (set-buffer rmail-buffer)
  1002.     (rmail-forward)
  1003.     (use-local-map (copy-keymap (current-local-map)))
  1004.     (define-key (current-local-map)
  1005.       "\C-c\C-c" 'rmail-summary-send-and-exit)))
  1006.  
  1007. ;; Summary output commands.
  1008.  
  1009. (defun rmail-summary-output-to-rmail-file ()
  1010.   "Append the current message to an Rmail file named FILE-NAME.
  1011. If the file does not exist, ask if it should be created.
  1012. If file is being visited, the message is appended to the Emacs
  1013. buffer visiting that file."
  1014.   (interactive)
  1015.   (save-excursion
  1016.     (set-buffer rmail-buffer)
  1017.     (call-interactively 'rmail-output-to-rmail-file)))
  1018.  
  1019. (defun rmail-summary-output ()
  1020.   "Append this message to Unix mail file named FILE-NAME."
  1021.   (interactive)
  1022.   (save-excursion
  1023.     (set-buffer rmail-buffer)
  1024.     (call-interactively 'rmail-output)))
  1025.  
  1026. ;; Sorting messages in Rmail Summary buffer.
  1027.  
  1028. (defun rmail-summary-sort-by-date (reverse)
  1029.   "Sort messages of current Rmail summary by date.
  1030. If prefix argument REVERSE is non-nil, sort them in reverse order."
  1031.   (interactive "P")
  1032.   (rmail-sort-from-summary (function rmail-sort-by-date) reverse))
  1033.  
  1034. (defun rmail-summary-sort-by-subject (reverse)
  1035.   "Sort messages of current Rmail summary by subject.
  1036. If prefix argument REVERSE is non-nil, sort them in reverse order."
  1037.   (interactive "P")
  1038.   (rmail-sort-from-summary (function rmail-sort-by-subject) reverse))
  1039.  
  1040. (defun rmail-summary-sort-by-author (reverse)
  1041.   "Sort messages of current Rmail summary by author.
  1042. If prefix argument REVERSE is non-nil, sort them in reverse order."
  1043.   (interactive "P")
  1044.   (rmail-sort-from-summary (function rmail-sort-by-author) reverse))
  1045.  
  1046. (defun rmail-summary-sort-by-recipient (reverse)
  1047.   "Sort messages of current Rmail summary by recipient.
  1048. If prefix argument REVERSE is non-nil, sort them in reverse order."
  1049.   (interactive "P")
  1050.   (rmail-sort-from-summary (function rmail-sort-by-recipient) reverse))
  1051.  
  1052. (defun rmail-summary-sort-by-correspondent (reverse)
  1053.   "Sort messages of current Rmail summary by other correspondent.
  1054. If prefix argument REVERSE is non-nil, sort them in reverse order."
  1055.   (interactive "P")
  1056.   (rmail-sort-from-summary (function rmail-sort-by-correspondent) reverse))
  1057.  
  1058. (defun rmail-summary-sort-by-lines (reverse)
  1059.   "Sort messages of current Rmail summary by lines of the message.
  1060. If prefix argument REVERSE is non-nil, sort them in reverse order."
  1061.   (interactive "P")
  1062.   (rmail-sort-from-summary (function rmail-sort-by-lines) reverse))
  1063.  
  1064. (defun rmail-sort-from-summary (sortfun reverse)
  1065.   "Sort Rmail messages from Summary buffer and update it after sorting."
  1066.   (require 'rmailsort)
  1067.   (pop-to-buffer rmail-buffer)
  1068.   (funcall sortfun reverse)
  1069.   (rmail-summary))
  1070.  
  1071. ;;; rmailsum.el ends here
  1072.